home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTALL.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  5KB  |  207 lines

  1. version    equ    0
  2.  
  3. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet receiver version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?,?,?
  44. handle        dw    ?
  45. packet_flag    dw    0
  46. first_count    dw    ?
  47. second_count    dw    ?
  48. signature    db    'PKT DRVR',0
  49. signature_len    equ    $-signature
  50. no_signature_msg    db    "No packet driver at that address",'$'
  51. usage_msg    db    "usage: pktall <packet_int_no>",'$'
  52. waiting_msg    label    byte
  53.     db    "Now waiting for packets to be received.  A dot will be printed when one is",CR,LF
  54.     db    "received.  Press any key to exit.",CR,LF,'$'
  55. counts_bad_msg    db    "First and second counts didn't match",CR,LF,'$'
  56. not_first_msg    db    "Driver maybe wrote too little",CR,LF,'$'
  57. not_second_msg    db    "Driver wrote too much",CR,LF,'$'
  58.  
  59.  
  60. usage_error:
  61.     mov    dx,offset usage_msg
  62. error:
  63.     mov    ah,9
  64.     int    21h
  65.     int    20h
  66.  
  67. start_1:
  68.     mov    dx,offset copyleft_msg
  69.     mov    ah,9
  70.     int    21h
  71.  
  72.     mov    si,offset phd_dioa+1
  73.     cmp    byte ptr [si],CR    ;end of line?
  74.     je    usage_error
  75.  
  76.     mov    di,offset packet_int_no
  77.     call    get_number
  78.  
  79.     mov    ah,35h            ;get their packet interrupt.
  80.     mov    al,packet_int_no
  81.     int    21h
  82.     mov    their_isr.offs,bx
  83.     mov    their_isr.segm,es
  84.  
  85.     lea    di,3[bx]
  86.     mov    si,offset signature
  87.     mov    cx,signature_len
  88.     repe    cmpsb
  89.     mov    dx,offset no_signature_msg
  90.     jne    error
  91.  
  92.     push    ds
  93.     mov    ax,1ffh            ;driver_info
  94.     int_pkt
  95.     pop    ds
  96.     call    fatal_error
  97.  
  98.     mov    ah,2            ;access all packets.
  99.     mov    al,ch            ;their class from driver_info().
  100.     mov    bx,dx            ;their type from driver_info().
  101.     mov    dl,cl            ;their number from driver_info().
  102.     mov    cx,0            ;type length of zero.
  103.     push    cs            ;es:di -> our receiver.
  104.     pop    es
  105.     mov    di,offset our_recv
  106.     int_pkt
  107.     call    fatal_error
  108.     mov    handle,ax
  109.  
  110.     mov    dx,offset waiting_msg
  111.     mov    ah,9
  112.     int    21h
  113.  
  114. wait_for_key:
  115.     cmp    packet_flag,0
  116.     je    no_packet
  117.  
  118.     mov    ax,first_count        ;do the counts match?
  119.     cmp    ax,second_count
  120.     je    counts_ok
  121.  
  122.     mov    ax,first_count
  123.     call    wordout
  124.  
  125.     mov    al,' '
  126.     call    chrout
  127.  
  128.     mov    ax,second_count
  129.     call    wordout
  130.  
  131.     mov    dx,offset counts_bad_msg
  132.     mov    ah,9
  133.     int    21h
  134. counts_ok:
  135.  
  136.     mov    bx,offset our_buffer    ;find the end of the buffer.
  137.     add    bx,first_count
  138.     cmp    [bx-1],bl        ;did we overwrite the first byte
  139.     jne    wrote_first        ;  of the magic value?
  140.     mov    dx,offset not_first_msg
  141.     mov    ah,9
  142.     int    21h
  143. wrote_first:
  144.  
  145.     cmp    [bx],bh            ;did we preserve the second byte
  146.     je    wrote_second        ;  of the magic value?
  147.     mov    dx,offset not_second_msg
  148.     mov    ah,9
  149.     int    21h
  150. wrote_second:
  151.  
  152.     mov    al,'.'
  153.     call    chrout
  154.  
  155.     mov    packet_flag,0
  156. no_packet:
  157.     mov    ah,1            ;check for any key.
  158.     int    16h
  159.     je    wait_for_key        ;no key -- keep waiting.
  160.  
  161.     mov    ah,0            ;fetch the key.
  162.     int    16h
  163.  
  164.     mov    ah,3
  165.     mov    bx,handle
  166.     int_pkt
  167.     call    fatal_error
  168.  
  169.     int    20h
  170.  
  171.  
  172. our_recv:
  173.     or    ax,ax            ;first or second call?
  174.     jne    our_recv_1        ;second -- bump the packet flag.
  175.     cmp    cs:packet_flag,0    ;Do we already have one?
  176.     jne    our_recv_2        ;yes - return zero.
  177.     push    cs
  178.     pop    es
  179.     mov    di,offset our_buffer
  180.     mov    bx,di            ;find the end of the buffer.
  181.     add    bx,cx
  182.     mov    cs:[bx-1],bx        ;store a magic value there.
  183.     mov    cs:first_count,cx    ;remember the first count.
  184.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  185. our_recv_2:
  186.     xor    di,di
  187.     mov    es,ax
  188.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  189. our_recv_1:
  190.     mov    cs:second_count,cx    ;remember the second count.
  191.     inc    cs:packet_flag
  192.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  193.  
  194.  
  195.     include    pkterr.asm
  196.     include    getnum.asm
  197.     include    getdig.asm
  198.     include    skipblk.asm
  199.     include    digout.asm
  200.     include    chrout.asm
  201.  
  202. our_buffer    label    byte
  203.  
  204. code    ends
  205.  
  206.     end    start
  207.